include("shared.lua")

--EXPERIMENTAL CODE! THIS DOESN'T YET WORK PROPERLY

--[[ function ENT:Initialize()
	self.contraption = {}
	self.pieces = 0
	self.active = false
	self.rendermaterial = Material("phoenix_storms/pack2/darkblue")
	self.rendermaterial:SetMaterialFloat("$alpha", 0.1)
	self.Initialized = false
	
	self.originalsettings = {}
	self.originalsettings.material = self.Entity:GetMaterial()
	self.originalsettings.color = Color(255, 255, 255, 255)
	self.originalsettings.model = self.Entity:GetModel()
	if self.originalsettings.model != "" then self.Initialized = true end
end

function ENT:Draw()
	self.BaseClass.Draw(self, true)
	self.Entity:DrawModel()
	--if self.Initialized then self.Entity:RenderShield() end
	local prerenderpos = self.Entity:GetPos()
	local prerenderorientation = self.Entity:GetAngles()
	if self.active then
		for number,item in pairs(self.contraption) do
			local alpha = math.Clamp((CurTime() - item.createtime), 0, 1) * 0.3
			self.rendermaterial:SetMaterialFloat("$alpha", alpha)
			local hullpiece = item.hull
			self.Entity:SetPos(item.hull:GetPos())
			self.Entity:SetAngles(item.hull:GetAngles())
			self.Entity:SetModel(item.hull:GetModel())
			--self.Entity:SetColor(255,255,255,alpha)
			--self.Entity:SetMaterial(self.rendermaterial)
			self.Entity:SetModelScale(Vector() * 1.1)
			SetMaterialOverride(self.rendermaterial)
			self.Entity:DrawModel()
			SetMaterialOverride(nil)
			self.Entity:SetModel(self.originalsettings.model)
			self.Entity:SetPos(prerenderpos)
			self.Entity:SetAngles(prerenderorientation)
		end
	end
	--self.Entity:SetMaterial(self.originalsettings.material)
	--self.Entity:SetColor(self.originalsettings.color)
end

function ENT:RenderShield()
	local prerenderpos = self.Entity:GetPos()
	local prerenderorientation = self.Entity:GetAngles()
	if self.active then
		for number,item in pairs(self.contraption) do
			local alpha = math.Clamp((CurTime() - item.createtime), 0, 1) * 70
			local hullpiece = item.hull
			--self.Entity:SetPos(item.hull:GetPos())
			--self.Entity:SetAngles(item.hull:GetAngles())
			self.Entity:SetModel(item.hull:GetModel())
			self.Entity:SetColor(255,255,255,alpha)
			self.Entity:SetMaterial(self.rendermaterial)
			self.Entity:SetModelScale(Vector() * 1.1)
			self.Entity:DrawModel()
			Msg("rendering shield model!\n")
		end
	end
	--self.Entity:ResetRendering()
	--self.Entity:SetPos(prerenderpos)
	--self.Entity:SetAngles(prerenderorientation)
end

function ENT:ResetRendering()
	self.Entity:SetModel(self.originalsettings.model)
	self.Entity:SetMaterial(self.originalsettings.material)
	self.Entity:SetColor(self.originalsettings.color)
end

function ENT:Think()
	if self.pieces != self.Entity:GetNetworkedInt("EffectCount") and self.active then
		self.pieces = self.Entity:GetNetworkedInt("EffectCount")
		for i=1,self.pieces do
			self.contraption[i] = {}
			local indexstring = "EffectHull" .. i
			self.contraption[i].hull = self.Entity:GetNetworkedEntity(indexstring)
			self.contraption[i].createtime = self.contraption[i].createtime or CurTime()
		end
	end
	if self.Entity:GetNetworkedBool("RenderShieldEffect") != self.active then
		self.active = self.Entity:GetNetworkedBool("RenderShieldEffect")
		self.pieces = 0
		self.contraption = {}
	end
	if not self.Initialized then self.Entity:Initialize() end
	self.Entity:NextThink(CurTime() + 0.1)
	--self.Entity:SetNoDraw(false)
	return true
end ]]